package core.avatar
{
	import Application.FirstApplication.def.Manager;
	
	import XComponent.hide.XEvent;
	import XComponent.show.XLoader;
	
	import com.friendsofed.isometric.IsoObject;
	
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.ApplicationDomain;
	import flash.utils.getDefinitionByName;

	public class AvatarBase extends IsoObject
	{
		private var loadFile : XLoader;
		private var avatar : MovieClip;
		
		private var avatarName : String;
		
		public function AvatarBase()
		{
			super(0);
		}
		
		public function build(avatarName : String):void
		{
			this.avatarName = avatarName;
			
			loadSwf(Manager.XML.Source.getUrl(avatarName));
			return;
		}
		
		public function loadSwf(url:String):void
		{
			loadFile = new XLoader;
			loadFile.load(url);
			
			loadFile.addEventListener(XLoader.LOAD_COMPLETE,OnLoadSrcComplete);
		}
		
		private function OnLoadSrcComplete(evt : XEvent):void
		{
			loadFile.removeEventListener(XLoader.LOAD_COMPLETE,OnLoadSrcComplete);
			
			var loader : Loader = evt.data;
			
			var avatarClass:Class = ApplicationDomain.currentDomain.getDefinition(avatarName) as Class;			
			
			avatar = (new avatarClass) as MovieClip;
			
			avatar.gotoAndStop(1);
			
			this.addChild(avatar);
		}
	}
}